Ext.namespace("Doc");

Doc.Fulfill = function (p){
	this.parentWin=p
	
	this.txtNum = new Ext.form.TextField({
        fieldLabel: '公文编号',
        name:'docNum',
        disabled:true,
        width: 120
    });
    this.hdSuperviseId = new Ext.form.Hidden({name:'superviseId'});
	this.txtTitle = new Ext.form.TextField({
        fieldLabel: '公文名称',
        name:'superviseTitle',
        width: 340,
        disabled:true
    });
	this.txtManagerId=new Ext.form.Hidden({name:'managerId'});
	this.txtManagerName = new Ext.form.TextField({
		fieldLabel: '阅处负责人',
		name:'managerName',
		width: 120,
		disabled: true
	});
	this.txtIssueDate = new Ext.form.TextField({
    	fieldLabel: '批示日期',
    	name:'issueDate',
		disabled:true,
		width:120
	});
	this.txtIssueType = new Ext.form.ComboBox({
		width: 120,
		fieldLabel: '公文类别',
		name:'issueType',
        store: new Ext.data.ArrayStore({
        	fields: ['value', 'name'],
        	data: OMS.DOC_TYPE2
        }),
        valueField: 'value',
        displayField: 'name',
        disabled:true,
        mode: 'local',
        triggerAction: 'all'
	});	
	this.txtNotion = new Ext.form.TextArea({
		fieldLabel: '领导批示意见',
		name:'notion',
		width: 540,
		height: 35,
		disabled:true
	});
	this.txtFulfill = new Ext.form.TextArea({
		fieldLabel: '落实情况',
		name:'fulfill',
		width: 540,
		height: 45,
		maxLength:1000
	});
	this.btnSave = new Ext.Button({
    	text:'保存',
    	handler:this.onSave,
    	scope: this
    });
	this.form = new Ext.form.FormPanel({
		bodyStyle: 'padding: 5px 5px 0',
        frame:true,
        labelWidth: 70,
		labelAlign:'right',
		region:'north',	
		height: 155,	
		split:true,
		collapsible: true,
		items:[this.txtManagerId,this.hdSuperviseId,
        	{ layout: 'column', border: false, defaults: {layout: 'form', border: false},
	        	items: [ { columnWidth: .66, items: [this.txtTitle]},
	        			 { columnWidth: .33, items: [this.txtNum] }]
	    },{ layout: 'column', border: false, defaults: {layout: 'form', border: false},
	        	items: [ { columnWidth: .33, items: [this.txtIssueType] },
	        			{ columnWidth: .33, items: [this.txtManagerName]},
	        	         { columnWidth: .33, items: [this.txtIssueDate]}]
	    },this.txtNotion,this.txtFulfill]
	});
	
	this.store2 = new Ext.data.JsonStore({
	    url: '../superviseDoc/listTask.form?timesnap=' + Date.parse(new Date()),
	    root: 'result',
	    totalProperty: 'total',
        remoteSort: true,
	    fields: ['auditId','superviseId','auditContent','auditorId','auditDate',
	    'auditState','inspectorId','inspectorName','dispatchDate','feedback','completeDate',
	    'content','auditorName']
	});
	//this.store.setDefaultSort('taskFeedbackId', 'desc');
	this.renderTaskStatus = function(value){
		return OMS.TASKSEXESTATUS[value];
	}
	this.renderState = function(value){
		return OMS.SUPERVISE_STATE[value];
	};
	this.btnCopy = new Ext.Button({
    	text: '复制',
    	iconCls: 'icon-update',
    	scope: this,
    	handler: this.onCopy
    });
	this.columns2 = [	
		{header: '派发ID', sortable: true, align: 'right',width: 20,hidden:true,dataIndex: 'auditId'},
		{header: '督办ID', sortable: true, align: 'right',width: 20,hidden:true,dataIndex: 'superviseId'},
		{header: '派发意见', sortable: true, align: 'center',width: 20,hidden:true,dataIndex: 'auditContent'},
		{header: '派发人ID', sortable: true, align: 'center',width: 20,hidden:true,dataIndex: 'auditorId'},
		{header: '派发人', sortable: true, align: 'center',width: 20,dataIndex: 'auditorName'},
		{header: '任务派发时间', sortable: true, align: 'right',width: 20,dataIndex: 'dispatchDate'},
		{header: '反馈日期', sortable: true, align: 'right',width: 20,hidden:true,dataIndex: 'auditDate'},
		{header: '状态', sortable: true, align: 'center',width: 20,dataIndex: 'auditState',renderer:this.renderState},
		{header: '阅处人id', sortable: true, align: 'center',width: 20,hidden:true,dataIndex: 'inspectorId'},
		{header: '阅处人名称', sortable: true, align: 'center',width: 20,hidden:true,dataIndex: 'inspectorName'},		
		{header: '反馈情况', sortable: true, align: 'center',dataIndex: 'feedback'},
		{header: '完成期限', sortable: true, align: 'right',width: 20,hidden:true,dataIndex: 'completeDate'}
	];
	this.grid2 = new Ext.grid.GridPanel({
		title:'任务派发情况',
		region: 'center',
		tbar: [this.btnCopy],
        cm: new Ext.grid.ColumnModel(this.columns2),
		store:this.store2,
		height: 100,
		viewConfig: { forceFit: true },
        collapsible:true
	});	
	Doc.Fulfill.superclass.constructor.call(this,{
		title: '公文督办反馈',
		width:700,
		height:420,
		resizable: false,
        modal: true,
        autoScroll: true,
		closeAction:'hide',
		items:[this.form,this.grid2],
		buttonAlign:'center',
		buttons:[this.btnSave,{
            text: '关闭',
            scope: this,
            handler: function() {
	        	this.hide();
        	}
        }]
	});	
};

Ext.extend(Doc.Fulfill, Ext.Window, {
	initWin:function(data){
		this.form.getForm().setValues(data);
		this.grid2.store.load({
			params:{superviseId:data.superviseId}
		});	
	},
	onSave: function() {
		if(!this.form.getForm().isValid()){
			Utils.info2("有必填项没有填写，请检查！",180);
			return;
		}
		var conn = new Ext.data.Connection({
  			url:'../superviseDoc/fulfill.form?timesnap=' + Date.parse(new Date()),
  			method:'post'
  		})
  		var param={superviseId:this.hdSuperviseId.getValue(),
  					fulfill:this.txtFulfill.getValue()};
  		//alert(Ext.util.JSON.encode(param));		
		Utils.request(conn,{
  			params:param,
  			scope:this,
  			success:function(data){
  				Utils.info2();
				this.scope.hide();
				this.scope.parentWin.queryDoc();
  			}
  		});
	},
	onCopy:function(){
		var value='';
		var count=this.store2.getCount();
		for(var i=0;i<count;i++){
			var data=this.store2.getAt(i).data;
			value+=data.auditorName+':'+data.feedback+";";
		}
		this.txtFulfill.setValue(value);
	}
});